package betandregret;

import java.util.ArrayList;
import java.util.Calendar;

public class Team { 
	private Sportart sportart;
	private String teamName;
	private final int id;
	private ArrayList<Spiel> spielCol = new ArrayList<Spiel>();

	Team(Sportart sportart, String name, int id) {
		this.setSportart(sportart);
		this.setTeamName(name);
		this.id = id;
	}

	public String getTeamName() {
		return teamName;
	}

	public void setTeamName(String teamName) {
		this.teamName = teamName;
	}

	public int getId() {
		return id;
	}

	public Sportart getSportart() {
		return sportart;
	}

	public void setSportart(Sportart sportart) {
		this.sportart = sportart;
	}

	public boolean sameSport(Team team) {
		return this.sportart.equals(team.getSportart());
	}

	public boolean istZeitraumFrei(Calendar startzeit, int dauer) {
		boolean available = true;
		Spiel current;
		
		for (int i = 0; i < spielCol.size() && available; i++) {
			current = spielCol.get(i);
			if (!(startzeit.getTimeInMillis() < current.getStartzeit()
					.getTimeInMillis() - (dauer * 60000) || startzeit
					.getTimeInMillis() > current.getStartzeit()
					.getTimeInMillis() + (dauer * 60000)))
				available = false;

		}

		return available;
	}

	public void addSpiel(Spiel spiel) {
		spielCol.add(spiel);

	}

}
